#ifndef MYVIEW_H
#define MYVIEW_H

#include <QtWebKit/QWebView>
#include <QMessageBox>
#include <QAction>
#include <QContextMenuEvent>
#include <QWebHitTestResult>
#include <QMenu>
#include <QNetworkRequest>
#include <QNetworkAccessManager>
#include <QUrl>
#include <QHttp>
#include <QProgressDialog>
#include <QString>
#include <QHttpResponseHeader>

#include "mainwindow.h"
class MainWindow;

class myWebView : public QWebView {
    Q_OBJECT

public:
    myWebView(QWidget *parent = 0);
    MainWindow *mainWindow();

protected:
   QUrl q;
   QNetworkRequest qnr;
   QWebView *createWindow(QWebPage::WebWindowType type);
    //QWebPage *createWindow(QWebPage::WebWindowType type);
    void contextMenuEvent(QContextMenuEvent *event);

private slots:
    void openLinkInNewTab(bool b);
    void saveLinkIntoFolder();
    void download(const QNetworkRequest &request, bool requestFileName = false);
    void cancelDownload();

    void httpRequestFinished(int requestId, bool error);
    void readResponseHeader(const QHttpResponseHeader &responseHeader);
    void updateDataReadProgress(int bytesRead, int totalBytes);

private:
    QUrl link;
    QString payload;
    QProgressDialog *progressDialog;
    QHttp *http;
    QFile *file;
    bool httpRequestAborted;
    int httpGetId;

};

#endif // MYVIEW_H
